package org.example.dataSource;

import lombok.Data;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

/**
 * org.example.dataSource
 *
 * @author 莫磊
 * @description 数据源的目的就是提供Connection对象，只要实现了DataSource的都是数据源
 * @date 2025/7/27
 */
@Data
public class MyDataSource implements DataSource {

	private String url;
	private String username;
	private String password;
	private String driver;
	@Override
	public Connection getConnection () throws SQLException {

		try {
			Class.forName(driver);
			return getConnection(username, password);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public Connection getConnection (String username, String password) throws SQLException {
		return DriverManager.getConnection(url, username, password);
	}

	@Override
	public PrintWriter getLogWriter () throws SQLException {
		return null;
	}

	@Override
	public void setLogWriter (PrintWriter out) throws SQLException {

	}

	@Override
	public void setLoginTimeout (int seconds) throws SQLException {

	}

	@Override
	public int getLoginTimeout () throws SQLException {
		return 0;
	}

	@Override
	public Logger getParentLogger () throws SQLFeatureNotSupportedException {
		return null;
	}

	@Override
	public <T> T unwrap (Class<T> iface) throws SQLException {
		return null;
	}

	@Override
	public boolean isWrapperFor (Class<?> iface) throws SQLException {
		return false;
	}
}
